﻿using CefSharp;
using CefSharp.WinForms;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web;
using System.Windows.Forms;

namespace MrytPub
{
    public partial class MainForm : Form
    {
        public static DateTime curDay;
        public ChromiumWebBrowser browser;
        public void InitBrowser()
        {
            //object p = Cef.GetGlobalCookieManager()..SetStoragePath(Environment.CurrentDirectory, true);
            browser = new ChromiumWebBrowser("https://zujuan.21cnjy.com/question?tree_type=knowledge&xd=2&chid=6");
            this.pn.Controls.Add(browser);
            browser.Dock = DockStyle.Fill;
            browser.LifeSpanHandler = new OpenPageSelf();
        }

        public MainForm()
        {
            InitializeComponent();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            InitBrowser();
            curDay = DateTime.Now;
            tb_pubdate.Text = curDay.ToString("yyyy-MM-dd");
        }

        private void bt_back_Click(object sender, EventArgs e)
        {
            if (browser.CanGoBack) browser.Back();
        }

        private void bt_forword_Click(object sender, EventArgs e)
        {
            if (browser.CanGoForward) browser.Forward();
        }

        private void bt_lisg_Click(object sender, EventArgs e)
        {
            PubForm pubForm = new PubForm("http://w.sfzd5.com/list.php", curDay);
            pubForm.Show();
        }

        private void bt_nextday_Click(object sender, EventArgs e)
        {
            curDay = curDay.AddDays(1);
            tb_pubdate.Text = curDay.ToString("yyyy-MM-dd");
        }

        private void bt_preday_Click(object sender, EventArgs e)
        {
            curDay = curDay.AddDays(-1);
            tb_pubdate.Text = curDay.ToString("yyyy-MM-dd");
        }

        private void bt_登录_Click(object sender, EventArgs e)
        {
            browser.Load("https://passport.21cnjy.com/login?jump_url=https%3A%2F%2Fzujuan.21cnjy.com%2Fu%2Fzujuan");
        }

        private void bt_浏览_Click(object sender, EventArgs e)
        {
            browser.Load("https://zujuan.21cnjy.com/question?tree_type=knowledge&xd=2&chid=6");
        }

        private void bt_记录_Click(object sender, EventArgs e)
        {
            browser.Load("https://zujuan.21cnjy.com/u/zujuan");
        }
    }
}
